package com.tianqu.tms.entity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.tianqu.tms.core.base.TmsEntity;
import com.tianqu.tms.core.exception.TmsDaoException;
import com.tianqu.tms.core.exception.TmsException;
import com.tianqu.tms.core.util.DateUtil;
import com.tianqu.tms.dao.TmsDao;
import com.tianqu.tms.dao.TransferSettlementDayDao;
import com.tianqu.tms.dto.TransferSettlementDayDto;

public class TransferSettlementDay extends TmsEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = -172817803918846308L;

	private int id;
	private String settleDate;
	private String settleUserId;
	
	
	public TransferSettlementDay getTransferSettlementDayInfo()throws TmsDaoException
	{
		TransferSettlementDayDao uDao = (TransferSettlementDayDao) TmsDao.getInstance(TmsDao.TMS_TRANSFER_SETTLEMENT_DAY);
		TransferSettlementDayDto dto = uDao.getTransferSettlementDayInfo();
		TransferSettlementDay entity = null;
		if(dto!=null)
		{
			entity = new TransferSettlementDay();
			entity.setId(dto.getId());
			entity.setSettleDate(DateUtil.getDateByTimeStamp(dto.getSettleDate()));
			entity.setSettleUserId(dto.getSettleUserId());
		}
		return entity;
	}
	public List getSettleDayInfo() throws TmsDaoException
	{
		TransferSettlementDayDao uDao = (TransferSettlementDayDao) TmsDao.getInstance(TmsDao.TMS_TRANSFER_SETTLEMENT_DAY);
		List<TransferSettlementDayDto> list = uDao.getSettleDayInfo();
		List dateList = null;
		if(list!=null)
		{
			dateList = new ArrayList();
			for(int i=0;i<list.size();i++)
			{
				TransferSettlementDayDto dto = (TransferSettlementDayDto)list.get(i);
				Map map = new HashMap();
				map.put("settlePeriodName", DateUtil.getDateByTimeStamp(dto.getSettleDate()));
				map.put("settlePeriodId", dto.getId());
				dateList.add(map);
			}
		}
		return dateList;
	}
	public TransferSettlementDay getSettleDayInfoByEndDate(String endDate)throws TmsDaoException
	{
		TransferSettlementDayDao uDao = (TransferSettlementDayDao) TmsDao.getInstance(TmsDao.TMS_TRANSFER_SETTLEMENT_DAY);
		TransferSettlementDay entity = null;
		String time = endDate.substring(0, 10)+" 00:00:00";
		TransferSettlementDayDto dto = uDao.getSettleDayInfoByEndDate(time);
		if(dto!=null)
		{
			entity = new TransferSettlementDay();
			entity.setId(dto.getId());
			entity.setSettleDate(DateUtil.getDateByTimeStamp(dto.getSettleDate()));
			entity.setSettleUserId(dto.getSettleUserId());
		}
		return entity;
	}
	public void updateSettleIdById(int id,String settleId)throws TmsDaoException
	{
		TransferSettlementDayDao uDao = (TransferSettlementDayDao) TmsDao.getInstance(TmsDao.TMS_TRANSFER_SETTLEMENT_DAY);
		TransferSettlementDayDto dto = new TransferSettlementDayDto();
		dto.setId(id);
		dto.setSettleUserId(settleId);
		uDao.updateSettleIdById(dto);
	}
	public int insertSettlementDayInfo(TransferSettlementDay entity)throws TmsDaoException
	{
		TransferSettlementDayDao uDao = (TransferSettlementDayDao) TmsDao.getInstance(TmsDao.TMS_TRANSFER_SETTLEMENT_DAY);
		TransferSettlementDayDto dto = new TransferSettlementDayDto();
		dto.setSettleUserId(entity.getSettleUserId());
		dto.setSettleDate(DateUtil.getStringToTimeStamp1(entity.getSettleDate()));
		return uDao.insertSettlementDayInfo(dto);
	}
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getSettleDate() {
		return settleDate;
	}

	public void setSettleDate(String settleDate) {
		this.settleDate = settleDate;
	}

	public String getSettleUserId() {
		return settleUserId;
	}

	public void setSettleUserId(String settleUserId) {
		this.settleUserId = settleUserId;
	}

	@Override
	public void save() throws TmsDaoException, TmsException {
		// TODO Auto-generated method stub

	}

}
